package com.huawei.cloud.phone.management.application.pkg.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.huawei.cloud.phone.management.common.validate.InstallGroup;
import com.huawei.cloud.phone.management.common.validate.UninstallGroup;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Objects;

@Data
public class PkgDTO {
    @NotNull(message = "参数中必须包含apk", groups = {InstallGroup.class, UninstallGroup.class})
    private ApkDTO apk;

    @NotNull(message = "参数中必须包含phone_info", groups = {InstallGroup.class, UninstallGroup.class})
    @JsonProperty("phone_info")
    @Valid
    private PhoneInfoDTO phoneInfo;

    public void setFiles(List<MultipartFile> files) {
        if (Objects.nonNull(apk)) {
            apk.setFiles(files);
        }
    }
}
